Skip to content

fix(h2): handle orphan streams left behind by aborted requests - #6147

Open
orshih6 wants to merge 1 commit into
nodejs:mainfrom
orshih6:contribot/issue-6143
Open

orshih6 wants to merge 1 commit into
nodejs:mainfrom
orshih6:contribot/issue-6143

Conversation

@orshih6

@orshih6 orshih6 commented Nov 3, 2026

Copy link
Copy Markdown

When a request on an established HTTP/2 session is aborted, undici closes the stream and destroys it synchronously, so Node stops tracking the JS stream object. If the server's response HEADERS for that stream arrive afterwards, Node's onSessionHeaders wraps the native stream in a new ClientHttp2Stream and emits it on the session's 'stream' event. undici had no 'stream' listener, so this orphan stream had no 'error' listener. When the idle timer later destroyed the session with InformationalError: socket idle timeout, Node passed that error to the orphan and it was thrown as an uncaught exception.

The client session now listens for 'stream'. Push is disabled, so this event only fires for these orphans. The handler attaches the existing noop error sink and closes the stream with NGHTTP2_CANCEL. This targets the stream that actually emits the unhandled error, so it also covers other error-based session teardowns, not just the idle timeout.

Testing:

  • Added test/issue-6143.js with the reproduction from the issue. It failed in every run before the change and passes consistently after it.
  • test/http2*.js, test/h2*.js, test/issue-5936.js, test/issue-5981.js and test/fetch/http2*.js pass.
  • eslint is clean.

🤖 Generated with Claude Code

Fixes #6143


This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.

Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
@orshih6

orshih6 commented Nov 17, 2026

Copy link
Copy Markdown
Author

Hi! Just checking in on this one. Is there anything you'd like changed, or anything else needed from my side? Happy to rework it, or to close it if it isn't a good fit. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/2: aborting fetch on an established session causes uncaught socket idle timeout

1 participant